<?php
class inman_api_product{
    public function __construct($app){
        $this->app=$app;
        $this->db = kernel::database();
        $this->goodsModel=kernel::single('b2c_mdl_goods');;
        $this->productsModel=kernel::single('b2c_mdl_products');
        $this->prepareModel=kernel::single('preparesell_mdl_preparesell');
        $this->prepareProductModel=kernel::single('preparesell_mdl_preparesell_goods');
    }
	/**
    获取商品的类目
    **/
	public function category($params,&$service){
		//获取顶级分类
		$categoryModel=kernel::single('b2c_mdl_goods_cat');
		$tops=$categoryModel->getList('cat_id,cat_name,parent_id',array('parent_id'=>'0'));
		if(!$tops){
				$error['status']='false';
				$error['message']=$this->app->_('没有找到数据');
				return $error;
		}
		foreach ($tops as &$top) {
			//子分类
			$top['sub_cat']=$categoryModel->getList('cat_id,cat_name,parent_id',array('parent_id'=>$top['cat_id']));
		}
		$return['category_list']=$tops;
		return $return;
	}
	/**
    商品列表
    **/
	public function getList($params,&$service){
		if(!isset($params['cat_id'])){
			$error['status']='false';
			$error['message']=$this->app->_('参数不正确');
			return $error;
		}
		 //根据分类查询
        if(isset($params['cat_id']) && $params['cat_id']!=null)
        {
           $filter['cat_id'] = $params['cat_id'];
        }
		//根据关键字查询
        if(isset($params['keyword']) && $params['keyword']!=null)
  		{
            $filter['search_keywords'] = array($params['keyword']);
        }
        $limit = $params['page_num'] ? $params['page_num'] : 10;
        $offset = $params['page_no'] ? (($params['page_no']-1) * $limit) : 0;
		 //排序
        if(isset($params['order']) && $params['order']>=0 && $params['order']<6)
        {
           	$order = $this->getOrder($params['order']);
            $orderBy = $order['sql'];
        }  
        $rows = $this->goodsModel->getList('*',$filter,$offset,$limit,$orderBy);
		 //组装返回的数据
        foreach ($rows as $key=>$row) {
            //是否预售
            $prepare=$this->prepareModel->getRow('*',array('goods_id'=>$row['goods_id']));
            //取预售的货品的第一件货品作为预售商品价格
            if($prepare){
                $prepareProduct=$this->prepareProductModel->getRow('preparesell_price,promotion_price',array('prepare_id'=>$prepare['prepare_id']));
            }
            //收藏统计
            $count=$this->getFocusNum($row['goods_id']);
            //vip
            $vip=kernel::single('b2c_mdl_goods_lv_price')->getRow('*',array('goods_id'=>$row['goods_id']));//取第一条vip记录
            //是否新品
            $is_new=$this->is_new($row['goods_id']);
            //获取商品图片
            $images=kernel::single('image_mdl_image_attach')->getList('image_id',array('target_id'=>$row['goods_id']));
            if(!$images){
            	$image_list='';
            }else{
            	foreach ($images as $k=>$image){
            		$image_list[$k]['color_code']='未知';
            		$image_list[$k]['img_url_small']=base_storager::image_path($image['image_id'],'small');
            		$image_list[$k]['img_url']=base_storager::image_path($image['image_id'],'large');
            	}
            	
            }
            
            
            
        	$data[$key]['goods_sn']=$row['bn'];
        	$data[$key]['is_new']=$is_new?'true':'false';
        	$data[$key]['collect_total']=$count?$count:0;
        	$data[$key]['is_collect']=$count?'true':'false';     	
        	$data[$key]['shop_price']=$row['price'];
        	$data[$key]['market_price']=$row['mktprice'];
        	$data[$key]['is_vip']=$vip?'true':'false';
        	$data[$key]['vip_price']=$vip?$vip['price']:0;		
        	$data[$key]['sales_number']=$row['buy_count']; 
        	$data[$key]['type']=$row['nostore_sell']?2:1;;
        	$data[$key]['deposit']= $prepare?$prepareProduct['preparesell_price']:0;
            $data[$key]['promo_price']=$prepare?$prepareProduct['promotion_price']:0;
            $data[$key]['balance']=$prepare?$prepareProduct['promotion_price']-$prepareProduct['preparesell_price']:0;
            $data[$key]['deposit_start_timestamp']=$prepare['prepare_id']?$prepare['begin_time']:0;
            $data[$key]['deposit_end_timestamp']=$prepare['prepare_id']?$prepare['end_time']:0;
            $data[$key]['balance_start_timestamp']=$prepare['prepare_id']?$prepare['begin_time_final']:0;
            $data[$key]['balance_end_timestamp']=$prepare['prepare_id']?$prepare['end_time_final']:0;
            $data[$key]['is_double_eleven_goods']='未知';  
            $data[$key]['the_start_price']='未知';   
            $data[$key]['the_description']=$prepare['prepare_id']?$prepare['description']:0;     
        	$data[$key]['img_list']=$image_list;

        }
        return array('product_list'=>$data);
		
	}
	//商品详情
    public function detail($params,&$service){
        if(!isset($params['goods_sn'])&&$params['goods_sn']!=null){
            $error['status']='false';
            $error['message']=$this->app->_('参数不正确');
            return $error;
        }
        $good=$this->goodsModel->getRow('*',array('bn'=>$params['goods_sn']));
        if(!$good)
        {
        	$error['status']='false';
            $error['message']=$this->app->_('没有数据');
            return $error;
        }
         //预售规则表找到预售商品
        $prepare=$this->prepareModel->getRow('*',array('goods_id'=>$good['goods_id']));
         //预售货品表找到一件预售货品(取第一条数据作为商品的预售商品)
        if($prepare){
            $prepareProduct=kernel::single('preparesell_mdl_preparesell_goods')->getRow('*',array('prepare_id'=>$prepare['prepare_id']));
        }
        
        //vip
        $vip=kernel::single('b2c_mdl_goods_lv_price')->getRow('*',array('goods_id'=>$good['goods_id']));//取第一条vip记录
        //收藏
        $count=$this->getFocusNum($good['goods_id']);

        $data['goods_sn']=$good['bn'];
        $data['goods_name']=$good['name'];
        $data['sales_number']=$good['buy_count'];
        $data['market_price']=$good['mktprice'];
        $data['shop_price']=$good['price'];
        $data['type']=$good['nostore_sell']?2:1;//预售、普通
        //ec预售是以货品为单位进行预售的
        $data['deposit']=$good['nostore_sell']? $prepareProduct['preparesell_price']:0;//预售订金
        $data['promo_price']=$good['nostore_sell']?$prepareProduct['promotion_price']:0;
        $data['balance']=$good['nostore_sell']?$prepareProduct['promotion_price']-$prepareProduct['preparesell_price']:0;
        $data['deposit_start_timestamp']=$prepare?$prepare['begin_time']:0;
        $data['deposit_end_timestamp']=$prepare?$prepare['end_time']:0;
        $data['balance_start_timestamp']=$prepare?$prepare['begin_time_final']:0;
        $data['balance_end_timestamp']=$prepare?$prepare['end_time_final']:0;
        $data['is_double_eleven_goods']='未知';   
        $data['the_start_price']='未知';   
        $data['the_description']='未知';      
        $data['is_vip']=$vip?'true':'false';
        $data['vip_price']=$vip?$vip['price']:0;
        $data['collect_total']=$count?$count:0;//收藏总数
        $data['comment_total']=$good['comments_count'];
        $data['is_collect']=$count?'true':'false';
        $data['integral']=$good['score'];
        $data['series_name']=$this->getPropsName($good['goods_id'],'季节');//'系列名称';
        $data['material_name']=$this->getPropsName($good['goods_id'],'质地');
        //return $good['spec_desc'];
        if($good['spec_desc']){
        	//有规格，读取规格,从货品表中读取颜色编码、尺寸
        	$color=$this->getColors($good['goods_id']);
        	$size=$this->getSizes($good['goods_id']);
        	$data['goods_color']=$color?$color:'';
	        $data['goods_size']=$size?$size:'';
	    
        }else{
        	$data['goods_color']='';
	        $data['goods_size']='';
        } 
        //查找货品
        $colors=$this->getAllSpecs('颜色');
        $sizes=$this->getAllSpecs('尺码');
        $products=$this->productsModel->getList('*',array('goods_id'=>$good['goods_id']));
        //return $products[0]['spec_desc'];
        foreach ($products as $key => $product) {
        	$data['inventory_info'][$key]['sku_sn']=$product['bn'];
        	if($product['spec_desc']&&!empty($colors)&&!empty($sizes)){
        		//颜色\、尺寸规格
        		foreach ($product['spec_desc']['spec_value_id'] as $value) {
        			if(in_array($value, $colors)){
        				$data['inventory_info'][$key]['color_code']='spec_value_id暂时作为颜色和尺寸编码:'.$value;//spec_value_id暂时作为颜色和尺寸编码
        				continue;
        			}
        			if(in_array($value, $sizes)){
        				$data['inventory_info'][$key]['size_code']='spec_value_id暂时作为颜色和尺寸编码:'.$value;
        				continue;
        			}
        		}
        	}else{
        		$data['inventory_info'][$key]['color_code']='';
        		$data['inventory_info'][$key]['color_name']='';
        	}
        	//可用库存
	        $data['inventory_info'][$key]['available_number']=$product['store']-$product['freez'];
        }
        //促销信息
        $promotions=kernel::single('b2c_mdl_goods_promotion_ref')->getList('*',array('goods_id'=>$good['goods_id']));
        if($promotions){
            foreach ($promotions as $key => $promotion) {
            	//根据sdb_b2c_goods_promotion_ref的字段tag_id来确定促销类型
            	$tag_name=kernel::single('desktop_mdl_tag')->getRow('tag_name',array('tag_id'=>$promotion['tag_id']));
                $data['promo_info'][$key]['pr_type']=$tag_name['tag_name'];
                $data['promo_info'][$key]['pr_name']=$promotion['description'];
            }           
        }else{
            $data['promo_info']='';
        }
        $data['size_table']='尺码表未知';
        $data['share_url']='分享地址未知';
        return $data;
    }
    public function getFocusNum($goods_id){
    	$count=$this->db->select('select count(*) as count from sdb_b2c_member_goods where goods_id='.$goods_id.' and type="fav"');
    	return ($count[0]['count']);
    }
    //商品搜索-关键词联想
    public function searchKeyThinking($params,&$service){
    	if(!isset($params['keyword'])&&$params['keyword']!=null){
    		$error['status']='false';
            $error['message']=$this->app->_('参数不正确');
            return $error;
    	}
    	$sql='select distinct keyword from sdb_b2c_goods_keywords where keyword like "%'.$params['keyword'].'%"';
    	$keywords=$this->db->select($sql);
    	if(!$keywords){
    		$error['status']='false';
            $error['message']=$this->app->_('没有找到数据');
            return $error;
    	}else{
    		return $keywords;
    	}	
    }
    //商品收藏
    public function collect($params,&$service){
    	if(isset($params['sid'])&&isset($params['goods_sn'])){//参数检测
			$member_id=$this->check_sid($params['sid']);
			if(!$member_id){
           	 	return $service->send_user_error('100001','sid fail');
        	}else{
        		$goods_id=$this->goodsModel->getRow('goods_id',array('bn'=>$params['goods_sn']));
        		$focusModel=kernel::single('b2c_mdl_member_goods');
        		$filter=array('goods_id'=>$goods_id['goods_id'],'type'=>'fav','member_id'=>$member_id);
        		$focus=$focusModel->getRow('gnotify_id',$filter);
        		if($focus){
        			//取消收藏(删除数据)
        			if($focusModel->delete($filter)){
        				return 0;
        			}
        		}else{
        			//添加收藏
        			$good=$this->goodsModel->getRow('goods_id,name,price,image_default_id',array('bn'=>$params['goods_sn']));
        			$data=array(
        				'goods_id'=>$good['goods_id'],
        				'member_id'=>$member_id,
        				'goods_name'=>$good['name'],
        				'goods_price'=>$good['price'],
        				'image_default_id'=>$good['image_default_id'],
        				'type'=>'fav',
        				'status'=>'ready',
        				'create_time'=>time(),
        				'object_type'=>'goods',
        			);
        			if($focusModel->insert($data)){
        				return 0;
        			}
        			
        		}
        	}
		}else{
			$error['status']='false';
            $error['message']=$this->app->_('参数不正确');
            return $error;
		}
    }
    //热销爆款（取商品）
    public function getHotGoods(){
    	$time=time()-100*24*3600;//15天前的时间
    	$sql="select goods_id,group_concat(number) from sdb_b2c_sell_logs where createtime> {$time} group by goods_id ";
    	$datas=$this->db->select($sql);
    	foreach ($datas as $key=>$data) {
    		//准备数据
    		$number=array_sum(explode(',',$data['group_concat(number)']));
       	    $good=$this->goodsModel->getRow('*',array('goods_id'=>$data['goods_id']));
       	    //预售
        	$prepare=$this->prepareModel->getRow('*',array('goods_id'=>$good['goods_id']));
        	//vip
        	$vip=kernel::single('b2c_mdl_goods_lv_price')->getRow('*',array('goods_id'=>$good['goods_id']));//去第一条vip记录
        	//收藏
        	$count=$this->getFocusNum($good['goods_id']);
        	//图片
        	$image_src=base_storager::image_path($good['image_default_id']);//原图路径
        	//新品
        	$is_new=$this->is_new($good['goods_id']);
       	    //组装数据
    		$goods[$key]['goods_sn']=$good['bn'];
    		$goods[$key]['is_new']=$is_new?'true':'false';
    		$goods[$key]['collect_total']=$count?$count:0;
    		$goods[$key]['is_collect']=$count?'true':'false';
    		$goods[$key]['market_price']=$good['mktprice'];
    		$goods[$key]['shop_price']=$good['price'];
    		$goods[$key]['is_vip']=$vip?'true':'false';
    		$goods[$key]['vip_price']=$vip?$vip['price']:0;
    		$goods[$key]['sales_number']=$good['buy_count'];
    		$goods[$key]['sales_15']=$number;
    		$goods[$key]['img_url']=$image_src;
    		$goods[$key]['color_code']='未知';
    		$goods[$key]['discount']='折扣未知';
    		$goods[$key]['is_double_eleven_goods']='未知';
    		$goods[$key]['the_start_price']='未知';
    		$goods[$key]['the_description']='未知';
    		//....
    	}
    	$return['product_list']=$goods;
    	return $return;
    }
    //商品评价列表
    public function getGoodsComment($params,&$service){
    	if(!isset($params['goods_sn'])||$params['goods_sn']==null){
			$error['status']='false';
			$error['message']=$this->app->_('参数不正确');
			return $error;
		}
		$goods_id=$this->goodsModel->getList('goods_id',array('bn'=>$params['goods_sn']));
		$commentModel=kernel::single('b2c_mdl_member_comments');
		$datas=$commentModel->getList('*',array('type_id'=>$goods_id['goods_id'],'object_type'=>'discuss'));
		foreach ($datas as $key => $data) {
			//回复（根据comment_id，找到for_comment_id）
			$answer=$commentModel->getRow('comment',array('for_comment_id'=>$data['comment_id']));
			$comment[$key]['user_name']=$data['author'];
			$comment[$key]['attr']='未知';
			$comment[$key]['comment_time']=date('Y-m-d H:i:s',$data['time']);
			$comment[$key]['comment_timestamp']=$data['time'];
			$comment[$key]['con tent']=$data['comment']; 
			//评论图片暂无，数据库待添加
			$comment[$key]['img_list']['thumb']='缩略图';
			$comment[$key]['img_list']['origin']='原图';
			$comment[$key]['is_answer']=$answer?'true':'false';
			$comment[$key]['answer']=$answer?$answer['comment']:'';		
		}
		$comments['comment_list']=$comment;
		return $comments;
    }
    //夏装新品类目
    public function getNewGoodsCagetory(){
    	$cateModel=kernel::single('b2c_mdl_goods_cat');
    	//inman那边固定夏装新品类目的cat_id
    	$cat_id=25;//本地添加id为25
    	$cate=$cateModel->getRow('cat_name',array('cat_id'=>$cat_id));
    	if(!$cate){
    		$error['status']='false';
			$error['message']=$this->app->_('暂无数据');
			return $error;
    	}
    	$nodes=$cateModel->getList('cat_id,cat_name',array('parent_id'=>$cat_id));
    	foreach ($nodes as $key => $node) {
    		$child[$key]['cat_id']=$node['cat_id'];
    		$child[$key]['name']=$node['cat_name'];
    		$child[$key]['img_url']='暂无';
    	}
    	$data['title']=$cate['cat_name'];
    	$data['category']=$child;
    	return $data;
    }
  //   //夏装新品(根据夏装新品的分类id，获取商品)
    public function getNewGoods($params,&$service){
    	if(!isset($params['cat_id'])||$params['cat_id']==null){
			$error['status']='false';
			$error['message']=$this->app->_('参数不正确');
			return $error;
		}
		//验证分类id是否是夏装新品的分类
		$id=25;//夏季新品的id
		$cateModel=kernel::single('b2c_mdl_goods_cat');
		$parent_id=$cateModel->getRow('parent_id',array('cat_id'=>$params['cat_id']));
		if($parent_id['parent_id']!=$id){
			$error['status']='false';
			$error['message']=$this->app->_('cat_id不正确');
			return $error;
		}
		$goods=$this->goodsModel->getList('*',array('cat_id'=>$params['cat_id']));
		if(!$goods){
			$error['status']='false';
			$error['message']=$this->app->_('暂无数据');
			return $error;
		}
		foreach ($goods as $key => $good) {
			 //是否预售
            $prepare=$this->prepareModel->getRow('*',array('goods_id'=>$good['goods_id']));
            //收藏统计
            $count=$this->getFocusNum($good['goods_id']);
            //图片
            //获取商品图片
            $images=kernel::single('image_mdl_image_attach')->getList('image_id',array('target_id'=>$good['goods_id']));
            if(!$images){
            	$image_list='';
            }else{
            	foreach ($images as $k=>$image){
            		$image_list[$k]['color_code']='未知';
            		$image_list[$k]['img_url_small']=base_storager::image_path($image['image_id'],'small');
            		$image_list[$k]['img_url']=base_storager::image_path($image['image_id'],'large');
            	}
            	 
            }

			$data[$key]['goods_sn']=$good['bn'];
			$data[$key]['shop_price']=$good['price'];
			$data[$key]['collect_total']=$count?$count:0;
			$data[$key]['is_collect']=$count?'true':'false';
			$data[$key]['is_double_eleven_goods']='未知';
			$data[$key]['the_start_price']='未知';
			$data[$key]['the_description']=$prepare?$prepare['description']:'';
			$data[$key]['img_list']=$image_list;
		}
		$products['product_list']=$data;
		return $products;

    }
    private function set_sid($member_id){
        kernel::single("base_session")->start();
        $member_ident = kernel::single("base_session")->sess_id();
        $sess_id = md5($member_ident.'api'.$member_id);
        kernel::single("base_session")->set_sess_id($sess_id);
        return $sess_id;
    }

    private function check_sid($accesstoken){
        $_GET['sess_id'] = $accesstoken;
        kernel::single("base_session")->start();
        $userObject = kernel::single('b2c_user_object');
        $id = $userObject->get_member_id();
        if($id){
        	return $id;
        }else{
        	return false;
        }
    }
    public function getOrder($id=null){
    	$order=array(
           0=>array('label'=>app::get('b2c')->_('不限制')),
           1=>array('label'=>app::get('b2c')->_('销量降序'),'sql'=>'buy_count desc'),
           2=>array('label'=>app::get('b2c')->_('销量升序'),'sql'=>'buy_count asc'),
           3=>array('label'=>app::get('b2c')->_('价格降序'),'sql'=>'price desc'),
           4=>array('label'=>app::get('b2c')->_('价格升序'),'sql'=>'price asc'),
           5=>array('label'=>app::get('b2c')->_('时间升序'),'sql'=>'uptime asc'),
           6=>array('label'=>app::get('b2c')->_('时间降序'),'sql'=>'uptime desc'),
        );
        if($id){
            return $order[$id];
        }else{
            return $order[1];
        }
    }
    public function  getColors($goods_id){
    	//获取商品的规格信息
    	$good_spec=$this->goodsModel->getRow('spec_desc',array('goods_id'=>$goods_id));
    	//获取规格表中所有颜色
    	$data=$this->getAllSpecs('颜色');
    	if(!$data){
    		return ;
    	}
    	$i=0;
    	foreach ($good_spec['spec_desc'] as $value) {
        		foreach ($value as $item) {
        			if(in_array($item['spec_value_id'], $data)){
        				$i++;
        				//获取颜色名称
        				$color_name=kernel::single('b2c_mdl_spec_values')->getRow('spec_value',array('spec_value_id'=>$item['spec_value_id']));
        				$return[$i]['color_code']='暂时以spec_vlue_id作为编码:'.$item['spec_value_id'];
        				$return[$i]['color_name']=$color_name['spec_value'];
        				//待确认
                        //判断图片有几个(是否有图片)
                        //....
                        $images=explode(',', $item['spec_goods_images']);
                        if(!empty($item['spec_goods_images'])){
                            foreach ($images as $key => $image) {
                                $return[$i]['gallery'][$key]['img_url']=base_storager::image_path($image,'small');//暂时给缩略小图
                                $return[$i]['gallery'][$key]['origin']=base_storager::image_path($image);
                            }
                        }else{
                            $return[$i]['gallery']='';
                        }
        				
        			}
        		}
        	}       	
        return $return;
    }
    public function  getSizes($goods_id){
    	//获取商品的规格信息
    	$good_spec=$this->goodsModel->getRow('spec_desc',array('goods_id'=>$goods_id));
    	//获取规格表中所有颜色
    	$data=$this->getAllSpecs('尺码');
    	if(!$data){
    		return ;
    	}
    	$i=0;
    	foreach ($good_spec['spec_desc'] as $key_1 => $value) {
        		foreach ($value as $key_2 => $item) {
        			if(in_array($item['spec_value_id'], $data)){
        				$i++;
        				//获取颜色名称
        				$size_name=kernel::single('b2c_mdl_spec_values')->getRow('spec_value',array('spec_value_id'=>$item['spec_value_id']));
        				$return[$i]['size_code']='暂时以spec_vlue_id作为编码:'.$item['spec_value_id'];
        				$return[$i]['size_name']=$size_name['spec_value'];
        			}
        		}
        	}
        return $return;
    }
    //获得指定规格的所有属性值(默认属性为‘颜色’)
    public function getAllSpecs($name='颜色'){
    	$spec_value_ids=kernel::single('b2c_mdl_specification')->getRow('spec_id',array('spec_name'=>$name));
    	if(!$spec_value_ids){
    		return ;
    	}
    	$spec_type_id=$spec_value_ids['spec_id'];
    	$specs=kernel::single('b2c_mdl_spec_values')->getList('spec_value_id',array('spec_id'=>$spec_type_id));
    	if(!$specs){
    		return ;
    	}
    	return $this->changeArr($specs);
    }
    
    //根据goods_id获取商品的扩展属性名称
    public function getPropsName($goods_id,$name='质地'){
        $goodTypePropValueModel=kernel::single('b2c_mdl_goods_type_props_value');
        //获取系列的id
        $series_id=kernel::single('b2c_mdl_goods_type_props')->getRow('props_id',array('name'=>$name));
        if(!$series_id){//没有系列属性
            return ;
        }
        //根据系列id获取系列的所有值
        $seriesValues=$goodTypePropValueModel->getList('props_value_id',array('props_id'=>$series_id['props_id']));
        if(!$seriesValues){//系列属性没有值
                return ;
        }
        $seriesValues=$this->changeArr($seriesValues);
        //读取商品数据库表的前10个扩展属性
        $num=$this->app->getConf('props.num');
        if(!$num){
            $num=10;
        }
        $good=$this->goodsModel->getRow('*',array('goods_id'=>$goods_id));
        for($i=1;$i<=$num;$i++){
            $props[]=$good['p_'.$i];
        }
        foreach ($props as $key => $prop) {
            if(in_array($prop, $seriesValues)){
                //根据$prop的值获取名称
                $name=$goodTypePropValueModel->getRow('name',array('props_value_id'=>$prop));
                return $name['name'];
            }

        }    
        return ;
    }
    private function changeArr($arrs){
        if(is_array($arrs)){
            foreach ($arrs as $arr) {
                foreach ($arr as $item) {
                    $return[]=$item;
                }
            }
            return $return;
        }else{
            return $arrs;
        }
    }
    //获得商品下面货品的所有的图片地址($type=true代表获取所有的图片)
    /**
     * @param unknown $good_id 商品id
     * @param string $num	返回图片的个数
     * @return array(
     * 			0=>...a
     * 			1=>...
     * )
     */
    private function getProductImagesByGoodId($good_id){
    	$images=kernel::single('image_mdl_image_attach')->getList('image_id',array('target_id'=>$good_id));
		if(!$images){
			return ;
		}
		foreach ($images as $image){
			$return[]=base_storager::image_path($image['image_id']);
		}
		return $return;
    }
    //商品是 否是新品
    /**
     * @param unknown $goods_id
     * @param string $name 标签名称
     * return bool
     */
    private function is_new($goods_id,$name='新品'){
    	$tag_id=kernel::single('desktop_mdl_tag')->getRow('tag_id',array('tag_name'=>$name));
    	if(!$tag_id){
    		return false;
    	}
    	//根据标签id，查看是否和商品关联
    	$data=kernel::single('desktop_mdl_tag_rel')->getRow('*',array('tag_id'=>$tag_id['tag_id'],'rel_id'=>$goods_id,'tag_type'=>'goods'));
    	if(!$data){
    		return false;
    	}
    	return true;
    }

}